<?php
namespace app\index\controller;

use think\curl;
use think\data;
use think\Cookie;
use app\index\controller\Index;
use think\Controller;
class About extends Index
{
    public function pull()
    {

     return view('about/pull', [
            'loginname' => Cookie::get('loginname')
        ]);

    }

    // 历史天气
    public function weather()
    {
       $curl = curl_init();
       // var_dump($curl);
       $apikey = 'aa41433ae00b2dea54e2b193362efa04';
       // $url = 'http://v.juhe.cn/historyWeather/citys?key='.$apikey.'&province_id=25&   weather_date=2018-10-10&day_weath';
       $now = date('Y-m-d',strtotime("-1 day"));
       // var_dump($now);
       $url = 'http://v.juhe.cn/historyWeather/weather?key='.$apikey.'&city_id=1844&weather_date='.$now;
       // CURL设置
       curl_setopt($curl, CURLOPT_URL, $url);
       // 将curl_exec()获取的信息以文件流的形式返回，而不是直接输出。
       curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
       // CURL  执行
       $data = curl_exec($curl);
       // var_dump($data); die;
       // 关闭CURL 
       curl_close($curl);
       $jsonObj = json_decode($data);
       // var_dump($jsonObj); exit;
       $weatherlist = $jsonObj->result;
        // $this->getWeather();
        return view('about/weather', [
            'weatherlist' => $weatherlist,
             'loginname' => Cookie::get('loginname')
        ]);
    }

    // 未来天气
    public function country()
    {
        $curl = curl_init();
        // var_dump($curl);
        $apikey = 'aa41433ae00b2dea54e2b193362efa04';
        // $url = 'http://v.juhe.cn/historyWeather/citys?key='.$apikey.'&province_id=25&   weather_date=2018-10-10&day_weath';
        $now = date('Y-m-d',strtotime("-1 day"));
        // var_dump($now);
        $url = 'http://v.juhe.cn/historyWeather/weather?key='.$apikey.'&city_id=1844&weather_date='.$now;
        // CURL设置
        curl_setopt($curl, CURLOPT_URL, $url);
        // 将curl_exec()获取的信息以文件流的形式返回，而不是直接输出。
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        // CURL  执行
        $data = curl_exec($curl);
        // var_dump($data); die;
        // 关闭CURL 
        curl_close($curl);
        $jsonObj = json_decode($data);
        // var_dump($jsonObj); exit;
        $weatherlist = $jsonObj->result;


        $curl = curl_init();
        // var_dump($curl);
        $apikey = '44de55895c53725be734cdb458c5b65f';
        $url = 'http://v.juhe.cn/weather/index?format=2&cityname=上海&key='.$apikey;
        // CURL设置
        curl_setopt($curl, CURLOPT_URL, $url);
        // 将curl_exec()获取的信息以文件流的形式返回，而不是直接输出。
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        // CURL  执行
        $data = curl_exec($curl);
        // var_dump($data);
        // 关闭CURL 
        curl_close($curl);
        $jsonObj = json_decode($data);
        // var_dump($jsonObj); exit;
        $country = $jsonObj->result;
        // var_dump($country->sk);
        // var_dump($country->today);
        // var_dump($country->future); exit;
         // $this->getWeather();
         return view('about/weather', [
            'weatherlist' => $weatherlist,
             'sk' => $country->sk,
             'today' => $country->today,
             'future' => $country->future,
              'loginname' => Cookie::get('loginname')
         ]);
    }



    public function _empty(Request $request)
    {
        return view('/error');
    }

}

